<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
    />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <link rel="stylesheet" href="/umi.css" />
    <script>
      window.routerBase = "/";
    </script>
    <script>
      //! umi version: 3.3.7
    </script>
    <title>M1芯片Mac上Homebrew安装</title>
  </head>
  <body>
    <div id="root"><div class="__dumi-default-layout" data-route="/guide/m1" data-show-sidemenu="true" data-show-slugs="true" data-site-mode="true" data-gapless="false"><div class="__dumi-default-navbar" data-mode="site"><button class="__dumi-default-navbar-toggle"></button><a class="__dumi-default-navbar-logo" style="background-image:url(&#x27;./images/homebrew-256x256.png&#x27;)" href="/">Homebrew</a><nav><div class="__dumi-default-search"><input type="search" class="__dumi-default-search-input" value=""/><ul></ul></div><span><a aria-current="page" class="active" href="/guide">指南</a></span><span><a target="_blank" rel="noopener noreferrer" href="https://github.com/ineo6/homebrew-install">GitHub<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="__dumi-default-external-link-icon"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></span></nav></div><div class="__dumi-default-menu" data-mode="site"><div class="__dumi-default-menu-inner"><div class="__dumi-default-menu-header"><a class="__dumi-default-menu-logo" style="background-image:url(&#x27;./images/homebrew-256x256.png&#x27;)" href="/"></a><h1>Homebrew</h1><p></p></div><div class="__dumi-default-menu-mobile-area"><ul class="__dumi-default-menu-nav-list"><li><a aria-current="page" class="active" href="/guide">指南</a></li><li><a target="_blank" rel="noopener noreferrer" href="https://github.com/ineo6/homebrew-install">GitHub<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="__dumi-default-external-link-icon"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div><ul class="__dumi-default-menu-list"><li><a target="_blank" rel="noopener noreferrer">介 绍</a><ul><li><a href="/guide"><span>介 绍</span></a></li><li><a href="/guide/how-it-works"><span>如何工作的？</span></a></li><li><a href="/guide/start"><span>快速开始</span></a></li></ul></li><li><a aria-current="page" class="active" href="/guide/m1">M1芯片 </a></li><li><a href="/guide/faq">FAQ</a></li></ul></div></div><ul role="slug-list" class="__dumi-default-layout-toc"><li title="安装 ARM 版 Homebrew" data-depth="2"><a href="/guide/m1#安装-arm-版-homebrew"><span>安装 ARM 版 Homebrew</span></a></li><li title="安装 X86 版 Homebrew" data-depth="2"><a href="/guide/m1#安装-x86-版-homebrew"><span>安装 X86 版 Homebrew</span></a></li><li title="多版本共存" data-depth="2"><a href="/guide/m1#多版本共存"><span>多版本共存</span></a></li><li title="设置镜像" data-depth="2"><a href="/guide/m1#设置镜像"><span>设置镜像</span></a></li></ul><div class="__dumi-default-layout-content"><div class="markdown"><h1 id="m1芯片mac上homebrew安装"><a aria-hidden="true" tabindex="-1" href="/guide/m1#m1芯片mac上homebrew安装"><span class="icon,icon-link"></span></a>M1芯片Mac上Homebrew安装</h1><p>目前<code>Homebrew</code>还没有完成对搭载<code>Apple Silicon CPU</code>的<code>Mac</code>机型完成适配，安装教程也比较混乱，所以我整理这篇文章，希望能帮到大家。</p><p>关于进度的信息可以浏览<code>GitHub</code>上的<a target="_blank" rel="noopener noreferrer" href="https://github.com/Homebrew/brew/issues/7857">说明<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="__dumi-default-external-link-icon"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>。</p><p>本文简单介绍了<code>M1</code>芯片<code>Mac</code>上安装<code>Homebrew</code>的方法，同时建议小伙伴结合 <a href="/guide/index">mac安装教程</a> 一起阅读并安装。</p><h2 id="安装-arm-版-homebrew"><a aria-hidden="true" tabindex="-1" href="/guide/m1#安装-arm-版-homebrew"><span class="icon,icon-link"></span></a>安装 ARM 版 Homebrew</h2><p><code>ARM</code>版<code>Homebrew</code>需要安装在<code>/opt/homebrew</code>路径下，早期的时候需要手动创建目录执行命令，目前使用最新脚本不需要手动操作。</p><p>直接执行：</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token plain">/bin/bash -c </span><span class="token string">&quot;</span><span class="token string variable">$(</span><span class="token string variable function">curl</span><span class="token string variable"> -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh</span><span class="token string variable">)</span><span class="token string">&quot;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p>或者使用我提供的脚本安装，好处是安装脚本可稳定访问，安装默认使用中科大镜像：</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token plain">/bin/bash -c </span><span class="token string">&quot;</span><span class="token string variable">$(</span><span class="token string variable function">curl</span><span class="token string variable"> -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh</span><span class="token string variable">)</span><span class="token string">&quot;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p>然后还需设置环境变量，在<code>~/.zprofile</code>或者<code>~/.bash_profile</code>文件末尾追加下面代码:</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token builtin class-name">export</span><span class="token plain"> </span><span class="token assign-left variable environment constant">PATH</span><span class="token operator">=</span><span class="token plain">/opt/homebrew/bin:</span><span class="token environment constant">$PATH</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p>具体操作步骤如下，一定要仔细阅读。</p><p>PS: 终端类型根据执行命令<code>echo $SHELL</code>显示的结果：</p><ul><li><code>/bin/bash</code> =&gt; <code>bash</code> =&gt; <code>.bash_profile</code></li><li><code>/bin/zsh</code> =&gt; <code>zsh</code> =&gt; <code>.zprofile</code></li></ul><p><strong>如果遇到环境变量无效问题，建议回过头来查看终端类型，再做正确的设置。</strong></p><p>从<code>macOS Catalina</code>(10.15.x) 版开始，<code>Mac</code>使用<code>zsh</code>作为默认<code>Shell</code>，使用<code>.zprofile </code>，所以对应命令：</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token builtin class-name">echo</span><span class="token plain"> </span><span class="token builtin class-name">export</span><span class="token plain"> </span><span class="token assign-left variable environment constant">PATH</span><span class="token operator">=</span><span class="token plain">/opt/homebrew/bin:</span><span class="token environment constant">$PATH</span><span class="token plain"> </span><span class="token operator">&gt;&gt;</span><span class="token plain"> ～/.zprofile </span></div><div class="token-line"><span class="token plain"></span><span class="token builtin class-name">source</span><span class="token plain"> ~/.zprofile</span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p>如果是<code>macOS Mojave</code> 及更低版本，并且没有自己配置过<code>zsh</code>，使用<code>.bash_profile</code>：</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token builtin class-name">echo</span><span class="token plain"> </span><span class="token builtin class-name">export</span><span class="token plain"> </span><span class="token assign-left variable environment constant">PATH</span><span class="token operator">=</span><span class="token plain">/opt/homebrew/bin:</span><span class="token environment constant">$PATH</span><span class="token plain"> </span><span class="token operator">&gt;&gt;</span><span class="token plain"> ～/.bash_profile </span></div><div class="token-line"><span class="token plain"></span><span class="token builtin class-name">source</span><span class="token plain"> ~/.bash_profile</span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p>扩展阅读：<a target="_blank" rel="noopener noreferrer" href="https://support.apple.com/zh-cn/HT208050">在 Mac 上将 zsh 用作默认 Shell<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="__dumi-default-external-link-icon"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p><h2 id="安装-x86-版-homebrew"><a aria-hidden="true" tabindex="-1" href="/guide/m1#安装-x86-版-homebrew"><span class="icon,icon-link"></span></a>安装 X86 版 Homebrew</h2><p>因为目前很多软件包没有支持<code>ARM</code>架构，我们也可以考虑使用<code>x86</code>版的<code>Homebrew</code>。</p><p>在命令前面添加<code>arch -x86_64</code>，就可以按X86模式执行该命令，比如：</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token plain">arch -x86_64 /bin/bash -c </span><span class="token string">&quot;</span><span class="token string variable">$(</span><span class="token string variable function">curl</span><span class="token string variable"> -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh</span><span class="token string variable">)</span><span class="token string">&quot;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div></pre></div><h2 id="多版本共存"><a aria-hidden="true" tabindex="-1" href="/guide/m1#多版本共存"><span class="icon,icon-link"></span></a>多版本共存</h2><p>如果你同时安装了ARM和X86两个版本，那你需要设置别名，把命令区分开。</p><p>同样是<code>.zprofile</code>或者<code>.bash_profile</code>里面添加：</p><p>至于操作哪个文件，请参考前文关于终端类型的描述，下文如有类似文字，保持一样的操作。</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token builtin class-name">alias</span><span class="token plain"> </span><span class="token assign-left variable">abrew</span><span class="token operator">=</span><span class="token string">&#x27;arch -arm64 /opt/homebrew/bin/brew&#x27;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token builtin class-name">alias</span><span class="token plain"> </span><span class="token assign-left variable">ibrew</span><span class="token operator">=</span><span class="token string">&#x27;arch -x86_64 /usr/local/bin/brew&#x27;</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p><code>abrew</code>、<code>ibrew</code>可以根据你的喜好自定义。</p><p>然后再执行<code>source ~/.zprofile</code>或<code>source ~/.bash_profile</code>命令更新文件。</p><h2 id="设置镜像"><a aria-hidden="true" tabindex="-1" href="/guide/m1#设置镜像"><span class="icon,icon-link"></span></a>设置镜像</h2><p><strong>注意：本文中的安装脚本会设置中科大源镜像，如果你也想设置<code>cask</code>和<code>bottles</code>的镜像，请按下面注释部分选择执行代码。</strong></p><p>更详细的教程可以参考前面的文章：<a href="/guide/start#part3">mac安装教程</a></p><p>执行时根据实际情况修改<code>&quot;$(brew --repo)&quot;</code>代码中的<code>brew</code>。</p><p>意思是如果你只是使用一个版本<code>Homebrew</code>，直接执行命令即可，如果你想多个版本共存或者使用了别名，就把<code>brew</code>关键字替换为别名名称，如前面的<code>abrew</code>、<code>ibrew</code>。</p><div class="__dumi-default-code-block"><pre class="prism-code language-shell"><button class="__dumi-default-icon __dumi-default-code-block-copy-btn" data-status="ready"></button><div class="token-line"><span class="token comment"># brew</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token function">git</span><span class="token plain"> -C </span><span class="token string">&quot;</span><span class="token string variable">$(</span><span class="token string variable">brew --repo</span><span class="token string variable">)</span><span class="token string">&quot;</span><span class="token plain"> remote set-url origin https://mirrors.ustc.edu.cn/brew.git</span></div><div class="token-line"><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token comment"># core</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token function">git</span><span class="token plain"> -C </span><span class="token string">&quot;</span><span class="token string variable">$(</span><span class="token string variable">brew --repo homebrew/core</span><span class="token string variable">)</span><span class="token string">&quot;</span><span class="token plain"> remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git</span></div><div class="token-line"><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token comment"># cask</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token function">git</span><span class="token plain"> -C </span><span class="token string">&quot;</span><span class="token string variable">$(</span><span class="token string variable">brew --repo homebrew/cask</span><span class="token string variable">)</span><span class="token string">&quot;</span><span class="token plain"> remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git</span></div><div class="token-line"><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token comment"># bottles for zsh 和下面2选1</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token builtin class-name">echo</span><span class="token plain"> </span><span class="token string">&#x27;export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles&#x27;</span><span class="token plain"> </span><span class="token operator">&gt;&gt;</span><span class="token plain"> ~/.zprofile</span></div><div class="token-line"><span class="token plain"></span><span class="token builtin class-name">source</span><span class="token plain"> ~/.zprofile</span></div><div class="token-line"><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token comment"># bottles for bash 和上面2选1</span><span class="token plain"></span></div><div class="token-line"><span class="token plain"></span><span class="token builtin class-name">echo</span><span class="token plain"> </span><span class="token string">&#x27;export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles&#x27;</span><span class="token plain"> </span><span class="token operator">&gt;&gt;</span><span class="token plain"> ~/.bash_profile</span></div><div class="token-line"><span class="token plain"></span><span class="token builtin class-name">source</span><span class="token plain"> ~/.bash_profile</span></div><div class="token-line"><span class="token plain"></span></div></pre></div><p>具体镜像设置参考<a href="/guide/start#part3">mac安装教程</a>=&gt;&quot;设置镜像&quot;一节。</p><p><strong>如果觉得教程有用，欢迎多多分享宣传～</strong></p></div><div class="__dumi-default-layout-footer-meta"><span data-updated-text="最后更新时间：">1970-1-1 8:00:00</span></div></div></div></div>
	<script>
  window.g_useSSR = true;
  window.g_initialProps = {};
	</script>

    <script src="/umi.js"></script>
  </body>
</html>
